package interview.removechars;

import java.util.HashMap;

public class RemoveChars {
	public String run(String target, String remove) {
		if(target == null || target.length() == 0)
			return null;
		
		if(remove == null || remove.length() == 0) {
			return target;
		}
		
		char[] tArray = target.toCharArray();
		char[] rArray = remove.toCharArray();
		
		HashMap<Character, Boolean> map = new HashMap<Character, Boolean>();
		for(char c : rArray) {
			map.put(c, true);
		}
		
		int ipointer, dpointer;
		dpointer = 0;
		
		for(ipointer = 0; ipointer < tArray.length; ipointer++) {
			if(map.get(tArray[ipointer]) == null) {
				tArray[dpointer] = tArray[ipointer];
				dpointer++;
			}
		}
		
		return new String(tArray, 0, dpointer);
	}
}
